﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using Newtonsoft.Json;

namespace Actya.Core.Security
{
	public class User : IPrincipal, IIdentity
	{
		public string Id { get; set; }
		public string Username { get; set; }
		public string PasswordHash { get; set; }
		public string PasswordSalt { get; set; }
		public string Email { get; set; }
		public DateTime DateCreated { get; set; }
		public DateTime? DateLastLogin { get; set; }
		public ICollection<string> Roles { get; set; }

		public bool IsInRole(string role)
		{
			return Roles.Any(r => r == role);
		}

		[JsonIgnore]
		public IIdentity Identity
		{
			get { return this; }
		}

		[JsonIgnore]
		public string Name
		{
			get { return this.Username; }
		}

		[JsonIgnore]
		public string AuthenticationType
		{
			get { return "CmsAuthentication"; }
		}

		[JsonIgnore]
		public bool IsAuthenticated { get; set; }

		public User()
		{
			Roles = new List<string>();
		}
	}
}
